<template>
  <div class="app-container">
    <hd-table-page
      ref="hdTable"
      :columns="columns"
      modulePath="system/kingOper"
      style="height: calc(100% - 100px)"
      :readOnly="true"
    >
      <template #actionButton="{ tableData, tableDataChild }">
        <el-button
          style="padding-left: 10px"
          size="mini"
          type="primary"
          icon="el-icon-refresh"
          @click="handleRepushs(tableData)"
          v-hasPermi="[modulePermi + ':repush']"
        >
          批量推送
        </el-button>
      </template>
      <template #query-operTime="{ data, field }">
        <hd-date-picker
          keyName="operTime"
          v-model="data.params"
        ></hd-date-picker>
      </template>
      <template #query-status="{ data, field }">
        <el-select
          v-model="data[field.prop]"
          placeholder="请选择"
          clearable
          style="width: 100%"
        >
          <el-option label="成功" value="0"></el-option>
          <el-option label="异常" value="1"></el-option>
        </el-select>
      </template>
      <template #operate="{ tableData, tableDataChild }">
        <el-table-column
          label="操作"
          width="120"
          fixed="right"
          :show-overflow-tooltip="true"
          align="center"
        >
          <template #default="scope">
            <el-button
              type="text"
              size="small"
              icon="el-icon-refresh"
              @click="handleRepush(scope.row)"
              v-if="scope.row.status == 1"
              v-hasPermi="[modulePermi + ':repush']"
            >
              重新推送
            </el-button>
          </template>
        </el-table-column>
      </template>
    </hd-table-page>
  </div>
</template>

<script>
//金蝶数据推送记录
// import { column_Repush } from '@/utils/columns'
import BaseService from "@/api/base/base";
const baseService = new BaseService("system/kingOper");
export default {
  name: "Repush",
  data() {
    return {
      modulePermi: "system:kingOper",
      columns: [
        { type: "selection", label: "#" },
        { prop: "idmDhzl", label: "单号指令", isSearch: false },
        { prop: "requestMethod", label: "对接方式", isSearch: false },
        { prop: "businessOrder", label: "来源单据" },
        { prop: "errorMsg", label: "错误消息", isSearch: false },
        { prop: "operTime", label: "操作时间" },
        {
          prop: "status",
          label: "操作状态",
          formatter: (row, col, val) => {
            return val == 0 ? "成功" : "异常";
          },
        },
      ],
    };
  },
  created() {},
  methods: {
    //重新推送
    handleRepush(row) {
      this.$confirm("是否确认重新推送?", "警告", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      }).then(() => {
        baseService.submit([{ ...row }]).then((res) => {
          this.$refs["hdTable"].getList();
          this.msgSuccess("提交成功");
        });
      });
    },
    handleRepushs() {
      var selection = this.$refs["hdTable"].tableData.selection;
      if (selection.every((item) => item.status === 1)) {
        this.$confirm("是否确认重新推送?", "警告", {
          confirmButtonText: "确 定",
          cancelButtonText: "取 消",
          type: "warning",
        }).then(() => {
          baseService.submit(selection).then((res) => {
            this.$refs["hdTable"].getList();
            this.msgSuccess("提交成功");
          });
        });
      } else {
        this.$message({
          type: "error",
          message: "存在推送成功的记录，不允许重新推送!",
        });
      }
    },
  },
};
</script>

<style module lang="scss"></style>
